﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Microsoft.VisualBasic;

namespace Frame
{
    public class Plugin : DockContent
    {
        protected readonly FrameApplication m_app;
        protected Size FloatSize { get; set; }
        //protected string m_type = PluginType.Default;
        //public PluginType Type { get{ return m_type; } }
        protected bool m_InitShow = false;  //初始化是否显示       
        public bool InitShow { get { return m_InitShow; } }
        protected bool m_inToolBar = false;//初始化是否显示在工具栏上
        public bool InToolBar { get { return m_inToolBar; } }
        protected Image toolBarIcon = null;
        public Image ToolBarIcon { get { return toolBarIcon; } }

        //protected Frame.Menu.MenuType m_menu = Frame.Menu.MenuType.OTHER;
        //public Frame.Menu.MenuType OnMenu { set { m_menu = value; } get { return m_menu; } }

        protected string m_menu = "OTHER";
        public string OnMenu { set { m_menu = value; } get { return m_menu; } }

        public Plugin() : base()
        {
            
        }

        public Plugin(FrameApplication app):base()
        {
            m_app = app;
            FloatSize = new Size(800, 600);
            HideOnClose = true;
            DefaultDockState = DockState.Document;
        }

        public DockPanel Panel { get; set; }
        public DockState DefaultDockState { get; set; }
        public virtual void InitUI() { /*throw new Exception(Type + "未重写InitUI方法");*/ }

        public virtual void InitialControlLanguage() { }

        new public void Show()
        {
            if (Panel!=null)
            {
                Show(Panel, DefaultDockState);
            }
            else
            {
                base.Show();
            }
        }

        protected override void OnDockStateChanged(EventArgs e)
        {
            if (this.DockState == DockState.Float)
            {
                foreach (var item in DockPanel.FloatWindows)
                {
                    if (item.Contains(this))
                    {
                        item.Size = FloatSize;
                        return;
                    }
                }
            }
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Plugin
            // 
            this.ClientSize = new System.Drawing.Size(477, 350);
            this.Name = "Plugin";
            this.ResumeLayout(false);

        }
    }
}
